package com.tjetc.controller;

import com.tjetc.entity.Users;
import com.tjetc.service.UsersService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.tjetc.util.R;
import javax.annotation.Resource;

/**
 * 前台用户表(Users)表控制层
 *
 * @author makejava
 * @since 2025-09-15 14:10:30
 */
@RestController
@RequestMapping("users")
public class UsersController {
    /**
     * 服务对象
     */
    @Resource
    private UsersService usersService;
    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("/login")
    public R login(String username, String password) {
        System.out.println(username);
        System.out.println(password);
        return  usersService.login(username, password);
    }
    /**
     * 分页查询
     *
     * @param users 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Users>> queryByPage(Users users, PageRequest pageRequest) {
        return ResponseEntity.ok(this.usersService.queryByPage(users, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("/id")
    public R queryById(Long uid) {
        return R.ok(this.usersService.queryById(uid));
    }
    @GetMapping("/uaccount")
     public R selectPageLikeUaccount(Integer pageNum,Integer pageSize,String uaccount,Integer utel) {return R.ok(this.usersService.selectPageLikeUaccount(pageNum,pageSize,uaccount,utel));}
    /**
     * 新增数据
     *
     * @param users 实体
     * @return 新增结果
     */
    @PostMapping("/register")
    public R add(@RequestBody Users users) {
        return this.usersService.insert(users);
    }

    /**
     * 编辑数据
     *
     * @param users 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public R edit(@RequestBody Users users) {
        return R.ok(this.usersService.update(users));
    }

    /**
     * 删除数据
     *
     * @param uid 主键
     * @return 删除是否成功
     */
    @GetMapping("/delete")
    public R deleteById(Long uid) {
        return R.ok(usersService.deleteById(uid));
    }
    @GetMapping("/queryByPage")
    public R queryByPage(Integer pageNum,Integer pageSize){
        return R.ok(usersService.Page(pageNum,pageSize));
    }
}

